-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Storage] Use structs for model types where appropriate #7807
Conversation
|
||
// Get response headers | ||
string _header; | ||
Azure.Core.Http.ETag eTag = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other variables are defined with _
prefix. While I like how they look without prefix we should be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure if we want that here. I prefixed the "well known variables" with an _
to avoid conflicts, but these are the sort of values that could cause conflicts with the _
variables. For example, if somebody adds a struct with a property called xml
, we wouldn't want that to conflict with our "well known variable" _xml
. I think this should probably change back what you originally had.
sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs
Outdated
Show resolved
Hide resolved
sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs
Outdated
Show resolved
Hide resolved
sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs
Outdated
Show resolved
Hide resolved
sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs
Outdated
Show resolved
Hide resolved
sdk/storage/generate.ps1
Outdated
@@ -10,7 +10,7 @@ autorest --use=$PSScriptRoot/Azure.Storage.Common/swagger/Generator/ --verbose | |||
cd $PSScriptRoot/Azure.Storage.Queues/swagger/ | |||
autorest --use=$PSScriptRoot/Azure.Storage.Common/swagger/Generator/ --verbose | |||
|
|||
cd $PSScriptRoot/Azure.Storage.Files.DataLake/swagger/ | |||
autorest --use=$PSScriptRoot/Azure.Storage.Common/swagger/Generator/ --verbose | |||
# cd $PSScriptRoot/Azure.Storage.Files.DataLake/swagger/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can comment this out and check it in. (The Storage folks checked in a work-in-progress that errors out.)
Use the Ordinal/OrginalIgnoreCase comparer for strings. |
Figure out if we need to compare byte arrays by value |
sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs
Outdated
Show resolved
Hide resolved
public class PageInfoTest | ||
{ | ||
[Test] | ||
public void EqualsReturnsTrueForEqualValues() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these tests are code-generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, these are hand written tests.
…arison and hash code generation
@tg-msft @pakrym Using StructuralComparisons.StructuralEquality for array comparison and HashCode generation. We cannot use |
|
||
namespace Azure.Storage.Blobs.Tests | ||
{ | ||
public class PageInfoTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment that these are related to our generated struct behavior so they make a little more sense to anyone else finding them in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I wasn't sure what this test was for at first.
@@ -24,5 +24,6 @@ | |||
--> | |||
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" Link="AzureCoreShared\%(RecursiveDir)\%(Filename)%(Extension)" /> | |||
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" Link="AzureCoreShared\%(RecursiveDir)\%(Filename)%(Extension)" /> | |||
<Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this end up placing the file? Do we want a Link="AzureCoreShared\...
like the other included files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was working as expected by using <Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" />
only, that's why I didn't realize about adding Link="AzureCoreShared\%(RecursiveDir)\%(Filename)%(Extension)"
.
I'll update it :)
|
||
// Get response headers | ||
string _header; | ||
Azure.Core.Http.ETag eTag = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure if we want that here. I prefixed the "well known variables" with an _
to avoid conflicts, but these are the sort of values that could cause conflicts with the _
variables. For example, if somebody adds a struct with a property called xml
, we wouldn't want that to conflict with our "well known variable" _xml
. I think this should probably change back what you originally had.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work Shivangi!
@@ -617,6 +626,17 @@ function generateOperation(w: IndentWriter, serviceModel: IServiceModel, group: | |||
}); | |||
} | |||
} | |||
if (response.struct) { | |||
w.line(); | |||
const Separator = IndentWriter.createFenceposter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - don't we case locals as separator
in TypeScript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I got confused between Typescript and .Net. Will update it.
w.line(`/// </summary>`); | ||
w.line(`/// <param name="obj">The instance to compare to.</param>`); | ||
w.line(`/// <returns>True if they're equal, false otherwise.</returns>`); | ||
w.line(`public override bool Equals(object obj) => obj is ${naming.type(type.name)} && Equals((${naming.type(type.name)})obj);`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pakrym - should we add an [EditorBrowsable(false)]
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
w.line(`/// <summary>`) | ||
w.line(`/// Get a hash code for the ${naming.type(type.name)}.`); | ||
w.line(`/// </summary>`); | ||
w.line(`public override int GetHashCode()`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should definitely add [EditorBrowsable(false)]
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
sdk/storage/Azure.Storage.Common/swagger/Generator/src/generator.ts
Outdated
Show resolved
Hide resolved
sdk/storage/Azure.Storage.Common/swagger/Generator/src/generator.ts
Outdated
Show resolved
Hide resolved
|
||
namespace Azure.Storage.Blobs.Tests | ||
{ | ||
public class PageInfoTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I wasn't sure what this test was for at first.
Changing the code generation to use structs for model types identified in the API review.
This PR changes the
AccountInfo
,PageInfo
andPageRange
models to use struct as per the guidelines .Here is the gist showing how the generated code would look like: https://gist.github.com/ShivangiReja/ccb498e4fba96452be7a52b156d17966